import React from 'react';
import { Form, Card, Row } from 'antd';
import { connect } from 'umi';
import { history } from 'umi'

import { withRoutePage } from '@/utils/enhanceUtils';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import { eventTrack } from '@/utils/track';

import { SearchForm, JobTable } from './components';

const List = ({ form, user, location }) => {
    const { companyId } = user.currentUser;
    const query = {
        current: 1,
        pageSize: 10,
        // companyId,
        ...location.query,
        showEmployeeNumber: 1 // 是否获取员工数
    };
    const setQuery = params => {
        history.push({ query: { ...params, showEmployeeNumber: 1 } });
    };

    React.useEffect(() => {
        eventTrack({
            eventName: 'personnel_management_organization_job_click',
            pageName: 'personnel_management_organization'
        });
    }, []);
    return (
        <PageHeaderWrapper>
            <Card bordered={false}>
                <SearchForm form={form} query={query} setQuery={setQuery} companyId={companyId} />
                <Row style={{ marginTop: 24 }}>
                    <JobTable query={query} setQuery={setQuery} />
                </Row>
            </Card>
        </PageHeaderWrapper>
    );
};

export default withRoutePage(
    connect(({ user }) => ({
        user
    }))(Form.create()(List))
);
